package web

import (
	"embed"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"io/fs"
	"net/http"
)

//go:embed assets favicon.svg
var sourceFs embed.FS

//go:embed index.html
var indexHtml string

func InitWebResource(router *gin.Engine) {
	httpFs := http.FS(sourceFs)
	err := fs.WalkDir(sourceFs, ".", func(path string, d fs.DirEntry, err error) error {
		if err == nil && !d.IsDir() {
			router.StaticFileFS(path, path, httpFs)
		}
		return err
	})
	if err != nil {
		zap.L().Fatal("初始化静态资源列表出现异常", zap.Error(err))
	}
	router.GET("/", indexHtmlFunc)
	router.GET("/check", indexHtmlFunc)
	router.GET("/login", indexHtmlFunc)
	router.GET("/register", indexHtmlFunc)
	router.GET("/forget", indexHtmlFunc)
}

func indexHtmlFunc(ctx *gin.Context) {
	ctx.Header("content-type", "text/html;charset=utf-8")
	ctx.String(http.StatusOK, indexHtml)
}
